/**      
 * @file		sequentialSearch.cpp
 * @description	This file demonstrates searching an array wiht a sequential sort.
 * @course		CSCI 123 Section 00000
 * @assignment 
 * @date		mm/dd/yyyy
 * @author		Brad Rippe (00000000) brippe@fullcoll.edu
 * @version		1.0
 */
#include <iostream>
#include <cstdlib>
using namespace std;

// function comments left out for brevity
int searchArray(const int aArray[], int aCurrentSize, int aElementToFind);
void fillArray(int aArray[], int aSize);
void outputArray(const int aArray[], int aSize);

/**
 * @return zero if the application executes successfully
 */
int main() {
	const int maxSize = 50;
	int numArray[maxSize];
	fillArray(numArray, maxSize);								// put numbers in the array

	cout << "The filled array is:\n";
	outputArray(numArray, maxSize);								// output the numbers in the array
	
	int numberToFind = 14;
	int found = searchArray(numArray, maxSize, numberToFind);	// search for zero
	
	if(found != -1) {
		cout << "Found " << numberToFind << " at location " << found << endl;
	} else {
		cout << "Did NOT find " << numberToFind << endl;
	}
	return 0;
}

void fillArray(int aArray[], int aSize) {
	int randNum;
	for(int i = 0; i < aSize; i++) {
		while(true) {
			randNum = (rand() % 100);						// create a random number
			if(searchArray(aArray, i+1, randNum) == -1) {	// check if the number 
				break;										// is in the array
			}												// if it is, search for a new number
		}
		aArray[i] = randNum;								// set the next element to the unique
	}														// random number; we won't have duplicate number
}															// numbers in the array

int searchArray(const int aArray[], int aCurrentSize, int aElementToFind) {
	for(int i = 0; i < aCurrentSize; i++) {
		if(aArray[i] == aElementToFind) {
			return i;
		}
	}
	return -1;
}

void outputArray(const int aArray[], int aSize) {
	for(int i = 0; i < aSize; i++)
		cout << aArray[i] << endl;
}

